const http = require('http')
const fs = require('fs')
const path = require('path')


const server = http.createServer()

server.on('request', (req, res) => {
  let url = req.url;
  let fpath = ''
  if(url === '/'){
    fpath = path.join(__dirname, './clock/newindex.html');
  } else {
    fpath = path.join(__dirname, './clock', url);
  }
  // console.log(fpath);
  fs.readFile(fpath, (err, data) => {
    if(err) return res.end('404 Not fount')

    res.end(data.toString());
  })
})

server.listen(8080, () => {
  console.log("server at http://127.0.0.1:8080")
})




